package mta.command.patch;

import mta.command.CommandIF;
import mta.io.LocalizationPackageWriter;
import mta.localization.LocalizationPackage;
import mta.localization.ModulePhrase;
import mta.patch.ModulePhrasePatchIF;

/**
 * Magento Translation Assistant
 * Copyright (c) 2009 Dmitry Nikolaev
 * Contact author: blackliteon@gmail.com
 */
public class Patch implements CommandIF {

    LocalizationPackage localization;
    ModulePhrasePatchIF mPatcher;
    LocalizationPackageWriter writer;

    public Patch(LocalizationPackage localization, ModulePhrasePatchIF mPatcher, LocalizationPackageWriter writer) {
        this.localization = localization;
        this.mPatcher = mPatcher;
        this.writer = writer;
    }

    public void execute() {
        for (ModulePhrase mPhrase : localization.getAllModulePhrases()) {
            String translation = mPatcher.getTranslation(mPhrase);

            if (translation != null && !translation.isEmpty()) {
                localization.setTranslationForModulePhrase(mPhrase, translation);
            }
        }

        writer.updatePackage(localization);
    }
}